import request from '@/utils/request'

// 定义请求地址的枚举
enum Api {
  GetUserList = '/admin.User/list', // 获取用户列表的接口地址
  RemoveUser = '/admin.User/dele', // 移除用户的接口地址
  SaveUser = '/admin.User/add', // 保存用户的接口地址
  UpdateUser = '/admin.User/edit', // 更新用户的接口地址
  GetAllRoleList = '/admin.Role/list', 
  GetUserRoleList='/admin.User/info', // 获取用户角色列表的接口地址
  AssignUserRoleList = '/admin.User/rule', // 设置用户角色的接口地址
  Jinyong ='/admin.User/disable'
}

/**
 * 获取用户分页列表
 * @param page 页码
 * @param limit 每页数量
 * @param searchParams 包含搜索条件的对象 {username: 'xxx'}
 * @returns UserPageListModel
 */
export const getUserListApi = (page:any,limit:any,nickname:any) => {
  return request.get<any, any>(Api.GetUserList +`?nickname=${nickname}&limit=${limit}&page=${page}`)
};

/**
 * 添加或更新用户
 * @param user 用户对象
 * @returns null
 */
export const saveOrUpdateUserApi = (user: any) => {
  if (user.admin_user_id) {
    return request.put<any, null>(Api.UpdateUser, user);
  }
  return request.post<any, null>(Api.SaveUser, user);
};

/**
 * 获取用户角色列表
 * @param userId 用户id
 */
export const getAllRoleListApi = () => {
  return request.get<any, any>(Api.GetAllRoleList);
};
export const getUserRoleListApi = (rid:any) => {
  return request.get<any, any>(Api.GetUserRoleList + `?admin_user_id=${rid}`);
};

/**
 * 给用户分配角色
 * @param userId 用户id
 * @param roleId 包含所有角色id的字符串 3,5,6
 * @returns 
 */
export const assignUserRoleListApi = (admin_user_id: string, admin_role_ids: string) => {
  return request.post<any, void>(Api.AssignUserRoleList,null, {
    params: {
      admin_user_id,
      admin_role_ids
    }
  });
};

/**
 * 删除用户
 * @param admin_user_id 用户id 
 * @returns null
 */
export const removeUserApi = (admin_user_id: string) => {
  return request.delete<any, null>(Api.RemoveUser + `?admin_user_id=${admin_user_id}`);
};

export const reqJinyong = ( id:any,is_disabled:any)=>{
  return request.get<any,any>(Api.Jinyong +`?admin_user_id=${id}&is_disable=${is_disabled}`)
}